######################################################
#Figure D6: Robustness Within Risk Type
#Author: Raluca L. Pahontu
#####################################################

data_rho2 <- read.dta13("robustwithin_rho2.dta")
library(tidyverse)
newdf_rho2 <- data_rho2 %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newdf_rho2$id <- c(1,2,3)
newdf_rho2$id <- as.factor(newdf_rho2$id)

g_rho2<- ggplot() + 
  geom_pointrange(data=newdf_rho2, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                               ymax=ci_lower), color="black", size=1.2, fatten=2, fill="black", shape=21) +
  scale_x_discrete(limit=c("1", "2", "3"), labels= c("!FT,!JT,JS", "!FT,JT,!JS", "!FT,!JT,!JS")) + 
  xlab("Indicator")  + ylab("Estimate on Social Spending Demand") +
  geom_hline(yintercept=0, col="black", lwd=0.4, lty="solid")  +  
  theme_bw() + 
  theme(legend.key=element_blank(),
        legend.text=element_text(color="black", size=10),
        panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
        panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
        axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
        axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
        axis.ticks.length=unit(0.3,"cm"),
        axis.text = element_text(colour ="black"))  + 
  coord_flip()  + 
  ylim(-.15,.15)
g_rho2


data_rho1 <- read.dta13("robustwithin_rho1.dta")
newdf_rho1 <- data_rho1 %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newdf_rho1$id <- c(1,2,3)
newdf_rho1$id <- as.factor(newdf_rho1$id)

g_rho1<- ggplot() + 
  geom_pointrange(data=newdf_rho1, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                               ymax=ci_lower), color="black", size=1.2, fatten=2, fill="black", shape=21) +
  scale_x_discrete(limit=c("1", "2", "3"), labels= c("JS,FT,!JT", "FT,JT,!JS", "FT,JS,JT,")) + 
  xlab("Indicator")  + ylab("Estimate on Social Spending Demand") +
  geom_hline(yintercept=0, col="black", lwd=0.4, lty="solid")  +  
  theme_bw() + 
  theme(legend.key=element_blank(),
        legend.text=element_text(color="black", size=10),
        panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
        panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
        axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
        axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
        axis.ticks.length=unit(0.3,"cm"),
        axis.text = element_text(colour ="black"))  + 
  coord_flip()  + 
  ylim(-.08,.08)
g_rho1

library(ggpubr)
ggarrange(g_rho2, g_rho1, ncol=2)
ggsave(file="figure_d6.eps")




